package com.sise.wangzhan.client;

import com.netflix.config.ConfigurationManager;
import com.sise.wangzhan.command.MyCommand;

/**
 * @Classname MyCommandClient
 * @Description TODO
 * @Date 2020/4/29 17:38
 * @Created by wangzhan
 */
public class MyCommandClient {
    public static void main(String[] args) {
        //10秒内有5个请求，满足第一个断路器开启条件
        ConfigurationManager.getConfigInstance().setProperty(
                "hystrix.command.default.metrics.rollingStats.timeInMilliseconds",10000
        );
        ConfigurationManager.getConfigInstance().setProperty(
                "hystrix.command.default.circuitBreaker.requestVolumeThreshold",5
        );
        // 请求的错误率超过50%  ,满足第二个断路器开启条件
        ConfigurationManager.getConfigInstance().setProperty(
                "hystrix.command.default.circuitBreaker.errorThresholdPercentage",50
        );


        for (int i = 1; i <= 15; i++) {
            //选好执行15次命令请求
            MyCommand myCommand = new MyCommand();
            myCommand.execute();

            //断路器是否开启
            if (myCommand.isCircuitBreakerOpen()){
                System.out.println("断路器被开启，执行第"+ i +" 个命令");
            }else {
                System.out.println("断路器未开启，需同时满足两个条件，执行第"+ i +" 个命令");
            }
        }


    }
}
